
import entities.Cerita;
import entities.Propinsi;
import entities.Users;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;

public class Demo {

    public static void main(String args[]) {

        Propinsi p = new Propinsi();

        p.setNama_propinsi("Jawa Timur");

        Users u = new Users();

        u.setUsername("admin");

        u.setNama("Admin Cerita Unyil");

        u.setPassword("admin");
        
        u.setAlamat("jember");
        
        u.setFoto(null);
        
        u.setGender(1);
        
        u.setPertanyaan(1);
        
        u.setJawaban("iya");

        Cerita c = new Cerita();

        c.setPropinsi(p);
        c.setJudul_cerita("Malin Kundang");
        c.setIsi_cerita("Cerita Maling Kundang ada disini...");

        Cerita c1 = new Cerita();

        c1.setPropinsi(p);
        c1.setJudul_cerita("Sangkuriang");
        c1.setIsi_cerita("Cerita Sangkuriang ada disini...");

        Demo demo = new Demo();

        demo.persist(u);
        //demo.persist(p);
        //demo.persist(c);
        //demo.persist(c1);

    }

    public void persist(Object object) {

        EntityManagerFactory emf = javax.persistence.Persistence.createEntityManagerFactory("CeritaUnyilPU");

        EntityManager em = emf.createEntityManager();

        em.getTransaction().begin();

        try {

            em.persist(object);

            em.getTransaction().commit();

        } catch (Exception e) {

            em.getTransaction().rollback();

        } finally {

            em.close();

        }

    }
}
